﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Aga.Psad.Common;
using Aga.Psad.Mvc.Helpers;
using Aga.Psad.Backend.Entities;

namespace Aga.Psad.Mvc.Models.Clientes
{
    public class ClienteDeClienteViewModel
    {
        public int Id { get; set; }
        public ClienteViewModel Cliente { get; set; }
        public string RazonSocial { get; set; }
        public string Cuit { get; set; }
        public string Usuario { get; set; }
        public int ExId { get; set; }
        public int Tipo { get; set; }

        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(RazonSocial))
                yield return new RuleViolation("Ingrese una Razón social", "RazonSocial");
            if (String.IsNullOrEmpty(Cuit))
                yield return new RuleViolation("Ingrese un CUIT", "Cuit");
            if (!CuitHelper.ValidaCuit(Cuit))
                yield return new RuleViolation("CUIT inválido", "Cuit");

            yield break;
        }

    }
}
